import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'

const routes: Array<RouteRecordRaw> = [{
  path:'/',
  redirect:'/HelloWorld'
}]
let views=require.context('../views',false,/\.vue$/)
let pathKey=views.keys()
console.log(pathKey,'路径')
let pathReg=/(?:\/).+(?<=\.)/
pathKey.forEach(item=>{
    let pathName=item.match(pathReg)?.[0].slice(0,-1)
    routes.push({
      path:`${pathName}`,
      name:`${pathName}`,
      component:()=>import(`@/views${pathName}.vue`)
    })
})



const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router
